#ifndef BOMLOADER_H
#define BOMLOADER_H

#include <vector>
#include <list>
#include <map>
using namespace std;

#include "tree.h"

typedef unsigned int uint;

class BomLoader
{
public:
    BomLoader();

    void loadBomRecords(const char* bomFile, const char *bomCompFile,
                        uint bomIdx_bomSeqId, uint bomIdx_assyId, uint bomIdx_assyOrgId,
                        uint bomCompIdx_bomSeqId, uint bomCompIdx_assyId,
                        uint bomCompIdx_itemId, uint bomCompIdx_orgId, uint bomCompIdx_usage );
    void filterBomRecords(vector<int> itemIds);

    void createBoms();
    void printBoms();

    ItemOrg* findItemOrg( int &itemId, int &orgId );
private:

    class BomRecord{
    public:
        BomRecord():
            isNeeded(true) {}
        bool isNeeded;
        int bomSeqId;
        int assyId;
        int orgId;
    };

    class BomCompRecord{
    public:
        BomCompRecord():
            isNeeded(true), needRevisit(true) {}

        bool needRevisit;
        bool isNeeded;
        int bomSeqId;
        int assyId;
        int orgId;
        int compId;
        double usage;
    };

    vector< BomRecord > bomRecords;
    vector< BomCompRecord > bomCompRecords;

    vector< ItemOrg* > bomTrees;
    multimap< unsigned int , ItemOrg* > itemMap;
    map< int, ItemOrg* > assemblyMap; // bill_seq_id -> assembly item-org
};

#endif // BOMLOADER_H
